package com.siwei.mes.entity.experiment.flyAsk;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.entity.experiment.slag.SlagSyhl;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 粉煤灰-三氧化硫
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FlyAskSyhl {
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "三氧化硫信息")
    private List<FlyAskSyhl.SyhlList> syhlList = Collections.singletonList(new FlyAskSyhl.SyhlList());


    @Data
    @Accessors(chain = true)
    @ApiModel("三氧化硫信息")
    public static class SyhlList {
        @ApiModelProperty(value = "换算系数")
        private String hsxs;
        @ApiModelProperty(value = "试样质量")
        private String syzl;
        @ApiModelProperty(value = "质量分数")
        private String zlfs;
        @ApiModelProperty(value = "瓷坩埚质量")
        private String zggzl;
        @ApiModelProperty(value = "称量器皿质量")
        private String clqmzl;
        @ApiModelProperty(value = "试样+器皿质量")
        private String slqmzl;
        @ApiModelProperty(value = "空白质量")
        private String kbsylzl;
        @ApiModelProperty(value = "灼烧后沉淀质量")
        private String zshcdzl;
        @ApiModelProperty(value = "灼烧后沉淀+瓷坩埚质量")
        private String zshcdcggzl;
    }


    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FlyAskSyhl entity = new FlyAskSyhl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FlyAskSyhl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FlyAskSyhl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FlyAskSyhl entity = JsonUtils.getObject(objJson, FlyAskSyhl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }
}
